package com.lds.employment.service.impl;

import java.util.Date;
import java.util.List;

import com.lds.employment.domain.EmploymentAssistance;
import com.lds.employment.domain.dto.AssistanceAndReservation;
import com.lds.employment.mapper.EmploymentAssistanceMapper;
import com.ruoyi.common.core.utils.bean.BeanUtils;
import io.swagger.models.auth.In;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.lds.employment.mapper.EmploymentInterviewMapper;
import com.lds.employment.domain.EmploymentInterview;
import com.lds.employment.service.IEmploymentInterviewService;
import org.springframework.transaction.annotation.Transactional;

/**
 * 面试登记Service业务层处理
 * 
 * @author ruoyi
 * @date 2024-01-05
 */
@Service
public class EmploymentInterviewServiceImpl implements IEmploymentInterviewService 
{
    @Autowired
    private EmploymentInterviewMapper employmentInterviewMapper;
    @Autowired
    private EmploymentAssistanceMapper assistanceMapper;

    /**
     * 查询面试登记
     * 
     * @param id 面试登记主键
     * @return 面试登记
     */
    @Override
    public EmploymentInterview selectEmploymentInterviewById(Long id)
    {
        return employmentInterviewMapper.selectEmploymentInterviewById(id);
    }

    /**
     * 查询面试登记列表
     * 
     * @param employmentInterview 面试登记
     * @return 面试登记
     */
    @Override
    public List<EmploymentInterview> selectEmploymentInterviewList(EmploymentInterview employmentInterview)
    {
        return employmentInterviewMapper.selectEmploymentInterviewList(employmentInterview);
    }

    /**
     * 新增面试登记
     * 
     * @param employmentInterview 面试登记
     * @return 结果
     */
    @Override
    public int insertEmploymentInterview(EmploymentInterview employmentInterview)
    {
        return employmentInterviewMapper.insertEmploymentInterview(employmentInterview);
    }

    /**
     * 修改面试登记
     * 
     * @param employmentInterview 面试登记
     * @return 结果
     */
    @Override
    public int updateEmploymentInterview(EmploymentInterview employmentInterview)
    {
        return employmentInterviewMapper.updateEmploymentInterview(employmentInterview);
    }

    /**
     * 批量删除面试登记
     * 
     * @param ids 需要删除的面试登记主键
     * @return 结果
     */
    @Override
    public int deleteEmploymentInterviewByIds(Long[] ids)
    {
        return employmentInterviewMapper.deleteEmploymentInterviewByIds(ids);
    }

    /**
     * 删除面试登记信息
     * 
     * @param id 面试登记主键
     * @return 结果
     */
    @Override
    public int deleteEmploymentInterviewById(Long id)
    {
        return employmentInterviewMapper.deleteEmploymentInterviewById(id);
    }

    @Override
    @Transactional
    public int insertInterviewAndAssistance(AssistanceAndReservation assistanceAndReservation) {
        EmploymentAssistance assistance = new EmploymentAssistance();
        BeanUtils.copyProperties(assistanceAndReservation,assistance);
        assistance.setCreateTime(new Date());
        System.out.println(assistance);
        EmploymentInterview interview = new EmploymentInterview();
        BeanUtils.copyProperties(assistanceAndReservation,interview);
        System.out.println(interview);

        int i = 0;
        int i1 = 0;
        if(assistance.getWeChat() != null){
            i = assistanceMapper.insertEmploymentAssistance(assistance);
        }
        if(interview.getCompanyName() !=null){
            i1 = employmentInterviewMapper.insertEmploymentInterview(interview);
        }

        return i+i1;
    }
}
